#import <Cocoa/Cocoa.h>

@interface FMICustomSlider : NSView
{
    NSGradient* gradient;
    CGFloat angle;
}

@property (nonatomic) NSGradient* gradient;
@property (nonatomic) CGFloat angle;


@end


#import "FMICustomSlider.h"

@implementation FMICustomSlider

@synthesize gradient;
@synthesize angle;

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame: frame];
    if (self) {
        self.gradient = [[NSGradient alloc] initWithStartingColor: [NSColor whiteColor] endingColor: [NSColor grayColor]];
        self.angle = 270;
        self.wantsLayer = YES;
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5.0;
        NSView *imView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 50, 50)];
//        imView.layer.backgroundColor = (__bridge CGColorRef)([NSColor purpleColor]);
        //NSImage *myImage = [[NSImage alloc] initByReferencingFile:@"knob.png"];
        //[imView setImage:myImage];
        [self addSubview:imView];
    }
    
    return self;
}

- (void)drawRect: (NSRect)dirtyRect
{
    if (self.gradient) {
        [self.gradient drawInRect: [self bounds] angle: self.angle];
        
        NSRect    imageRect, controlRect;
        NSImage *myImage = [[NSImage alloc] initByReferencingFile:@"knob.png"];
        imageRect.origin.x = 0.0;
        imageRect.origin.y = 0.0;
        imageRect.size = [myImage size];
        controlRect = [self bounds];
//        [myImage drawInRect:imageRect
//                       fromRect:controlRect
//                      operation:NSCompositeCopy
//                       fraction:1.0];
        //[myImage drawInRect:imageRect fromRect:dirtyRect operation:NSCompositeCopy fraction:1.0];
        
    }
    else {
        NSLog(@"No gradient set up for ACTGradientView: %@", self);
    }
}

-(void)setGradient:(NSGradient*)gr
{
  
    if (![self.gradient isEqualTo: gr]) {
        gradient = gr;
        
        [self setNeedsDisplay: TRUE];
    }
}

-(void)setAngle:(CGFloat)an
{
    angle = an;
    [self setNeedsDisplay: TRUE];
}
@end
